package com.lagou.code.controller;

import com.lagou.code.service.CodeService;
import com.lagou.common.vo.MsgCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/code")
public class CodeController {
    @Autowired
    CodeService codeService;
    @RequestMapping("/createCode")
    public MsgCode createCode(@RequestParam String email){
        //生成验证码
        int i = (int) ((Math.random() * 9 + 1) * 100000);
        String  registCode = i+"";
        //将验证码和邮箱号保存到数据库
        codeService.deleteMsgCode(email);
        codeService.insertMsgCode(registCode,email);
        MsgCode msgCode = new MsgCode();
        msgCode.setEmail(email);
        msgCode.setRegistCode(registCode);
        return msgCode;
    }
}
